<?php
session_start();

$currentUser = isset($_SESSION["user"])?$_SESSION["user"]:null;
if(!$currentUser){
    echo "未登录";
    die(0);
}

$title = $_POST["Title"];
$content = $_POST["Content"];
$createTime = (new DateTime())->FORMAT('Y-m-d H:i:s');
$updateTime = $createTime;
$authorId = $currentUser["Id"]; 
$authorName = $currentUser["Username"];

$sql="INSERT INTO `Article`
(`Title`,`Content`,`CreateTime`,`UpdateTime`,`AuthorId`,`AuthorName`)
VALUES
('$title','$content','$createTime','$updateTime','$authorId','$authorName')";
  
$conn = new mysqli("localhost","root",'','myblog');

$conn->query($sql);

if($conn->error) echo $conn->error;
else{
    echo "添加成功,<a href='article_list.php'>跳转到列表</a>";
}
?>